package com.jinzhuo;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class workQueueConsumer {
    public static void main(String[] args) throws IOException, TimeoutException {

        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername("jinzhuo");
        factory.setPassword("jinzhuo");
        factory.setVirtualHost("/jinzhuo");

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("workQueue",true,false,false,null);

        DefaultConsumer consumer = new DefaultConsumer(channel){
            //回调对象
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
//                super.handleDelivery(consumerTag, envelope, properties, body);
                System.out.println("数据="+new String(body));
            }
        };
        channel.basicConsume("workQueue",true,consumer);
    }
}
